//
//  VVCloseComponent.m
//  ComponentLinkDemo
//
//  Created by wenchao on 17/3/3.
//  Copyright © 2017年 zhenby. All rights reserved.
//

#import "VVCloseComponent.h"
#import "CLActionEvent.h"
#import "VVActionIdentifier.h"

@interface VVCloseComponent ()

@property (nonatomic) UIButton* btnClose;

@end

@implementation VVCloseComponent

- (void)loadView
{
    UIButton* closebtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closebtn setTitle:@"X" forState:UIControlStateNormal];
    [closebtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    closebtn.frame = CGRectMake(10, 10, 30, 30);
    self.btnClose = closebtn;
    [self.parentController.view addSubview:closebtn];
    
    [closebtn addTarget:self action:@selector(onHandleCloseAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)onHandleCloseAction:(UIButton*)sender
{
    CLActionEvent* event = [CLActionEvent actionWithName:kCloseActionIdentifier customData:nil];
    [self postActionEvent:event];
}

- (void)actionObserverWithEvent:(CLActionEvent*)action
{
    if ([action.actionName isEqualToString:kCloseActionIdentifier]) {
        [self.parentController dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
}

//提供服务事件处理
- (nullable NSDictionary*)actionServiceWithEvent:(CLActionEvent*)action
{
    if ([action.actionName isEqualToString:kCloseServiceAction]) {
        return @{@"closekey":@(100)};
    }
    return nil;
}

@end
